package org.loofer.uikit;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;
import java.util.HashSet;
import java.util.Iterator;

public class ExtendScrollView extends ScrollView {
    private HashSet<Integer> mScrollableChildren;
    private Rect mTmpRect = new Rect();

    public ExtendScrollView(Context context) {
        super(context);
    }

    public ExtendScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ExtendScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void addScrollableChild(int childId) {
        if (childId != 0) {
            if (this.mScrollableChildren == null) {
                this.mScrollableChildren = new HashSet();
            }
            this.mScrollableChildren.add(Integer.valueOf(childId));
        }
    }

    public void removeScrollableChild(int childId) {
        if (this.mScrollableChildren != null) {
            this.mScrollableChildren.remove(Integer.valueOf(childId));
        }
    }

    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (shouldDeliverToChild(event)) {
            return false;
        }
        return super.onInterceptTouchEvent(event);
    }

    private boolean shouldDeliverToChild(MotionEvent event) {
        if (this.mScrollableChildren != null) {
            Rect hitRect = this.mTmpRect;
            int x = (int) (event.getX() + ((float) getScrollX()));
            int y = (int) (event.getY() + ((float) getScrollY()));
            Iterator it = this.mScrollableChildren.iterator();
            while (it.hasNext()) {
                Integer id = (Integer) it.next();
                if (id != null) {
                    View child = findViewById(id.intValue());
                    if (child != null && child.getVisibility() == 0) {
                        child.getHitRect(hitRect);
                        if (hitRect.contains(x, y)) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
}
